import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

class Solution {
    private List<Integer> path;
    private int sum;
    public int subsetXORSum(int[] nums) {
        path = new ArrayList<>();
        dfs(nums, 0);
        return sum;
    }
    private void dfs(int[] nums, int i) {
        if(i == nums.length) {
            int tmp = 0;
            Iterator<Integer> it = path.iterator();
            while(it.hasNext()) {
                tmp ^= it.next();
            }
            sum += tmp;
            return;
        }
        path.add(nums[i]);
        dfs(nums, i+1);
        path.remove(path.size()-1);
        dfs(nums, i+1);
    }
}